import request from '@/utils/request';

export const messageApi = {
  // 获取腾讯云通信凭证
  getTencentCredentials: () => {
    return request.get<{
      userID: string;
      userSig: string;
      SDKAppID: number;
    }>('/tencent-im/tencent-credentials');
  },
  
  // 获取消息列表
  getMessageList: (params: {
    conversationID?: string;
    count?: number;
    lastMessageID?: string;
  }) => {
    return request.get('/message/list', { params });
  },
  
  // 发送消息
  sendMessage: (data: {
    conversationID: string;
    content: string;
    type: 'text' | 'image' | 'file' | 'video' | 'audio';
    payload?: any;
  }) => {
    return request.post('/message/send', data);
  },
  
  // 获取会话列表
  getConversationList: () => {
    return request.get('/message/conversation/list');
  },
  
  // 创建群聊
  createGroup: (data: {
    name: string;
    type: string;
    memberList: string[];
    avatar?: string;
    introduction?: string;
  }) => {
    return request.post('/message/group/create', data);
  },
  
  // 加入群聊
  joinGroup: (groupID: string) => {
    return request.post(`/message/group/join/${groupID}`);
  },
  
  // 退出群聊
  quitGroup: (groupID: string) => {
    return request.post(`/message/group/quit/${groupID}`);
  },
  
  // 获取群成员列表
  getGroupMembers: (groupID: string) => {
    return request.get(`/message/group/members/${groupID}`);
  }
};